home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / relnotes / shared / mkindex.sh < prev    next >
Text File  |  2002-10-07  |  5KB  |  207 lines

  1. #!/sbin/sh
  2. #
  3. # Create an HTML index from the installed Freeware products based
  4. # on the release notes.
  5. #
  6. # usage: $0 [-installed|-web]
  7. # -installed     create index.html and index for installed products.
  8. # -web        create web pages (i.e. leave out installed.html)
  9. # -web is designed for internal SGI use only; generate pages for silicon surf.
  10. #
  11. # -installed is the default
  12. #
  13. # input: $COMMON/index.template, $COMMON/*.data
  14. # output: $RELDIR/index.html, $RELDIR/installed.html, $RELDIR/*.html
  15. #
  16.  
  17. # Generic template sections.
  18. TITLE="TITLE"
  19. HIGHLIGHTS="HIGHLIGHTS"
  20. SIDENAV="SIDENAV"
  21. CONTENTS="CONTENTS"
  22.  
  23. # Freeware-specific sections.
  24. INST_ED="INSTALLED INDEX"
  25. INST_ABLE="INSTALLABLE INDEX"
  26. HTTP_LINK="HTTPLINKS"
  27. FILE_LINK="FILELINKS"
  28.  
  29.  
  30. #######################
  31. ## begin subroutines ##
  32. #######################
  33.  
  34. # rmsection $input_file $section
  35. rmsection()
  36. {
  37.     sed -e "/<!-- BEGIN $2 -->/,/<!-- END $2 -->/d" <$1 >$TMP
  38.     mv -f $TMP $1
  39. }
  40.  
  41. # applyfilters $input_file
  42. applyfilters()
  43. {
  44.     [ true = $RMINSTED ]   && rmsection $1 "$INST_ED"
  45.     if [ ! -f $RELDIR/index-by-alpha.html ]; then  ## fw_latest is not available
  46.         [ true = $RMINSTABLE ] && rmsection $1 "$INST_ABLE"
  47.     fi
  48.     [ true = $RMHTTPLINK ] && rmsection $1 "$HTTP_LINK"
  49.     [ true = $RMFILELINK ] && rmsection $1 "$FILE_LINK"
  50. }
  51.  
  52.  
  53. # mergetemplate $template $data $result
  54. mergetemplate()
  55. {
  56.     template=$1
  57.     data=$2
  58.     result=$3
  59.  
  60.     rm -f $result $TMP
  61.  
  62.     # Splice the title and contents sections into the template.
  63.     sed -n -e "1,/<!-- BEGIN $TITLE -->/p" $template                         > $TMP
  64.     sed -n -e "/<!-- BEGIN $TITLE -->/,/<!-- END $TITLE -->/p" $data        >> $TMP
  65.     sed -n -e "/<!-- END $TITLE -->/,/<!-- BEGIN $CONTENTS -->/p" $template >> $TMP
  66.     sed -n -e "/<!-- BEGIN $CONTENTS -->/,/<!-- END $CONTENTS -->/p" $data  >> $TMP
  67.     sed -n -e "/<!-- END $CONTENTS -->/,\$p" $template                      >> $TMP
  68.     mv -f $TMP $result
  69.  
  70.     # Remove any unwanted generic template sections
  71.     if grep -q -e "<!-- NO $SIDENAV -->" $data; then
  72.     rmsection $result "$SIDENAV"
  73.     fi
  74.     if grep -q -e "<!-- NO $HIGHLIGHTS -->" $data; then
  75.     rmsection $result "$HIGHLIGHTS"
  76.     fi
  77.  
  78.     # Let data files override normal template sections.
  79.     if grep -q -e "<!-- NO $INST_ED -->" $data; then
  80.     rmsection $result "$INST_ED"
  81.     fi
  82.     if grep -q -e "<!-- NO $INST_ABLE -->" $data; then
  83.     rmsection $result "$INST_ABLE"
  84.     fi
  85.     if grep -q -e "<!-- NO $HTTP_LINK -->" $data; then
  86.     rmsection $result "$HTTP_LINK"
  87.     fi
  88.     if grep -q -e "<!-- NO $FILE_LINK -->" $data; then
  89.     rmsection $result "$FILE_LINK"
  90.     fi
  91. }
  92.  
  93.  
  94. # makeinstalled $input_file $output_file
  95. makeinstalled()
  96. {
  97.     rm -f $TMP.data
  98.     cat >> $TMP.data <<EOF
  99. <!-- BEGIN $TITLE -->
  100. <TITLE>Installed Freeware</TITLE>
  101. <META NAME="keywords"    CONTENT="SGI, IRIX, freeware, shareware, GNU, Linux">
  102. <META NAME="description" CONTENT="Index of installed freeware packages">
  103. <META NAME="owner"       CONTENT="freeware@sgi.com">
  104. <!-- END $TITLE -->
  105.  
  106. <!-- BEGIN $CONTENTS -->
  107. <H2>Installed Freeware</H2>
  108. <UL>
  109. EOF
  110.  
  111.     # Parse each release note and add an entry.  The entry will consist
  112.     # of the title as represented in the <TITLE> identifier and a link
  113.     # to the actual release note
  114.     # first egrep -v is for files created by fw_common
  115.     # second egrep -v is for files created by fw_latest
  116.     # last egrep is to remove empty lines
  117.     for FILE in `cd $RELDIR && \
  118.         ls -1 *.html | \
  119.         egrep -v "(installed|index|contributors|faq|fw|howto|index-alt|mirrors|legal_notice).html" | \
  120.         egrep -v "index-(by-alpha|by-category|by-date|alt).html" | \
  121.         egrep -v "^$" `
  122.     do
  123.     # sed -e 1q == head -1
  124.     # sed -e 's/.*>\(.*\)>.*/\1/' == cut -f2- -d'>' | cut -f1 -d'<'
  125.     #    to get the parts between <title>(I WANT THIS PART)</title>
  126.     title=`grep -i '<TITLE>' $RELDIR/$FILE | \
  127.         sed -e '1q' | \
  128.         sed -e 's/.*>\(.*\)<.*/\1/' `
  129.     echo "<LI><A HREF=\"$FILE\">$title</A>"        >>$TMP.data
  130.     done
  131.  
  132.     # Create the footer information
  133.     cat >> $TMP.data <<EOF
  134. </UL>
  135. <!-- END $CONTENTS -->
  136. EOF
  137.  
  138.     mergetemplate $1 $TMP.data $2
  139.     rm -f $TMP.data
  140. }
  141.  
  142. #####################
  143. ## end subroutines ##
  144. #####################
  145.  
  146.  
  147. # Parse command line option; default to -installed
  148. if [ "$1" = '' ] ; then
  149.     MODE=-installed 
  150. else
  151.     MODE=$1;
  152. fi
  153.  
  154. # default is to remove all index.html link sections
  155. RMINSTED=true
  156. RMINSTABLE=true
  157. RMHTTPLINK=true
  158. RMFILELINK=true
  159. # default is to create only the index.html file
  160. MKINSTALLED=false
  161. # set command line option
  162. case $MODE in 
  163.     -installed)  ## default
  164.     RMINSTED=false
  165.     MKINSTALLED=true
  166.     RMFILELINK=false
  167.     RELDIR=${rbase:=/}/usr/freeware/relnotes
  168.     ;;
  169.     -web)
  170.     echo "                                       WEB"
  171.     RMINSTABLE=false
  172.     RMHTTPLINK=false
  173.     RELDIR=.
  174.     ;;
  175. esac
  176.  
  177. COMMON=$RELDIR/shared  ## MUST NOT CHANGE. same location as old fw_common
  178. INDEX=$RELDIR/index.html
  179. INST=$RELDIR/installed.html
  180. TMP=/tmp/mkindex.$$
  181.  
  182. # Remove the previous index if one exists
  183. # Create the index.html ($INDEX)
  184. rm -f $INDEX
  185. cp $COMMON/index.template $TMP.start
  186. applyfilters $TMP.start
  187. mv -f $TMP.start $INDEX
  188.  
  189. # Create installed.html ($INST)
  190. if [ true = $MKINSTALLED ]; then
  191.     rm -f $INST
  192.     makeinstalled $COMMON/index.template $TMP.inst
  193.     applyfilters $TMP.inst
  194.     mv -f $TMP.inst $INST
  195. fi
  196.  
  197. # Process data files
  198. for file in $COMMON/*.data; do
  199.     base=`basename $file .data`
  200.     rm -f $RELDIR/$base.html
  201.     mergetemplate $COMMON/index.template $file $TMP.$base
  202.     applyfilters $TMP.$base
  203.     mv -f $TMP.$base $RELDIR/$base.html
  204. done
  205.  
  206. exit 0
  207.